﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IrishSettings;
using IrishSettings.Installation;

namespace SampleWebForms
{
    public partial class _Default : System.Web.UI.Page
    {
        /// <summary>
        /// This would be something static
        /// </summary>
        public class TestSettings : SettingsApplication
        {
            public TestSettings()
            {
                Construct(new Version(1, 0));
            }

            public TestSettings(Version v)
            {
                Construct(v);
            }

            private void Construct(Version v)
            {
                Application = "TestApp";
                CultureObject = new CultureInfo("en-US");
                VersionObject = v;
                Schema.ValidateAndAdd("culture", Schema.StringItem("culture", "en-US", CultureObject)); //is-is
                Schema.ValidateAndAdd("timezone", Schema.StringItem("timezone", "EST", CultureObject));
                Schema.ValidateAndAdd("fiscalStart", Schema.IntItem("fiscalStart", 10, CultureObject));
                Schema.ValidateAndAdd("workdayStart", Schema.IntItem("workdayStart", 8, CultureObject));
                Schema.ValidateAndAdd("workdayEnd", Schema.IntItem("workdayEnd", 16, CultureObject));
                Schema.ValidateAndAdd("earliestHitDate", Schema.StringItem("earliestHitDate", "1/1/2011", CultureObject));
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //DbApplicationManager manager = new DbApplicationManager();
            if (!IsPostBack)
            {
                IrishSettingsManager m1 = new IrishSettingsManager(new TestSettings());
                m1.Save();
                this.CurrentSettings.DataSource = m1.Enumeration();
                CurrentSettings.DataBind();
            }
        }

        protected void InstallToDatabase_Click(object sender, EventArgs e)
        {
            InstallIrishSettings.CreateAllTables("ApplicationServices", "dbs_");
        }
    }
}
